import assert from "assert";
import {readFileSync} from "fs";
import {resolve, dirname} from "path";
// 此URL.fileURLToPath函数将文件URL解码为路径字符串，并确保在将给定的文件URL转换为路径时正确地附加/调整了URL控制字符(/，％)
import {fileURLToPath} from "url";
import * as modules from "../src/build.js";
// import.meta.url 包含了对于目前 ES 模块的绝对 URL 路径
const packagePath = resolve(dirname(fileURLToPath(import.meta.url)), "../package.json");
const packageData = JSON.parse(readFileSync(packagePath));

for (const moduleName in packageData.mocha) {
  it(`module exports everything from ${moduleName}`, async () => {
    const module = await import(moduleName);
    for (const propertyName in module) {
      if (propertyName !== "version") {
        assert(propertyName in modules, `${moduleName} exports ${propertyName}`);
      }
    }
  });
}
